﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace WindowsGame2
{
    class HUD
    {
        //player scores, X = P1, Y = P2
        private Point m_score;
        private float m_p1ScoreWidth, m_p2ScoreWidth, m_dividerWidth;
        private int m_scoreOffset;
        private String m_dividerString = " | ";

        public Point Score 
        {
            get { return m_score; }            
        }

        public HUD()
        {
            m_score = Point.Zero;
            m_p1ScoreWidth = Assets.SpriteFont1.MeasureString(m_score.X.ToString()).X;
            m_p2ScoreWidth = Assets.SpriteFont1.MeasureString(m_score.X.ToString()).X;
            m_dividerWidth = Assets.SpriteFont1.MeasureString(m_dividerString).X;
            m_scoreOffset = 20;
        }

        public void UpdateScoreP1(int a_points)
        {
            m_score.X += a_points;
            m_p1ScoreWidth = Assets.SpriteFont1.MeasureString(m_score.X.ToString()).X;
        }

        public void UpdateScoreP2(int a_points)
        {
            m_score.Y += a_points;
            m_p2ScoreWidth = Assets.SpriteFont1.MeasureString(m_score.Y.ToString()).X;
        }

        public void Draw(SpriteBatch a_spriteBatch, int a_screen_width)
        {
            //Player 1 score
            a_spriteBatch.DrawString(Assets.SpriteFont1,
                m_score.X.ToString(),
                new Vector2((a_screen_width / 2) - (m_scoreOffset + m_p1ScoreWidth), 10),
                Color.DeepSkyBlue);

            //divider
            a_spriteBatch.DrawString(Assets.SpriteFont1,
                m_dividerString,
                new Vector2(a_screen_width / 2, 10),
                Color.Yellow,
                0,
                new Vector2(m_dividerWidth / 2, 0),
                1,
                SpriteEffects.None,
                1);

            //Player 2 score
            a_spriteBatch.DrawString(Assets.SpriteFont1,
                m_score.Y.ToString(),
                new Vector2((a_screen_width / 2) + m_scoreOffset, 10),
                Color.DeepSkyBlue);
        }
    }
}
